package com.zym.testpoi.service.impl;

import com.zym.testpoi.pojo.Class;
import com.zym.testpoi.pojo.User;
import com.zym.testpoi.service.UserService;
import com.zym.testpoi.util.DownloadUtil;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;

@Service
public class UserServiceImpl implements UserService {
    @Override
    public void download(List<Object> list,List<String> sheetNameList, HttpServletResponse response) throws IOException {
        List<Map<String,Object>> sheet1List = new LinkedList<>();
        List<Map<String,Object>> sheet2List = new LinkedList<>();
        
        List<User> userList = (List<User>) list.get(0);
        List<Class> classList = (List<Class>) list.get(1);

        for (User user : userList) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("用户名",user.getUsername());
            map.put("年龄",user.getAge());
            map.put("爱好",user.getHobby());
            sheet1List.add(map);
        }

        for (Class aClass : classList) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("班级ID",aClass.getClassId());
            map.put("班级名称",aClass.getClassName());
            sheet2List.add(map);
        }

        List dataList = new LinkedList();
        dataList.add(sheet1List);
        dataList.add(sheet2List);

        DownloadUtil.downloadMoreSheet(dataList,sheetNameList,response);
    }
}
